<?php
namespace app\admin\controller;
use think\Db;
class Qiandao extends Base
{
	public function lists(){
        
        //ajax查询数据
        if( is_post() ){
            $page     = input('page');
            
            
            $is_lianxu= input('is_lianxu');
            $keyword  = input('keyword');
            $min_time = input('min_time');
            $max_time = input('max_time');
            
            //原生态sql查询
            $sql = "
                select
                    [1]
                from
                    order_qiandao_points oqp
                left join
                    user u
                on
                    oqp.user_id=u.id
                where 
                    1 = ?
                ";
            $param = [1];
            if ( $is_lianxu != '100all' ) {
                $sql .= " and oqp.is_lianxu = ?";
                $param[] = $is_lianxu;
            }
            if ( !empty($keyword) ) {
                $sql .= " and u.name like ?";
                $param[] = "%{$keyword}%";
            }
            if ( !empty($min_time) ) {
                $sql    .= " and oqp.create_time >= ?";
                $param[] = strtotime($min_time);
            }
            if ( !empty($max_time) ) {
                $sql    .= " and oqp.create_time <= ?";
                $param[] = strtotime($max_time);
            }
            //总条数
            $sql_count = str_replace("[1]", "count(*) as total", $sql);
            $total     = Db::query($sql_count, $param);
            $total     = $total[0]['total'];
            
            //分页数据
            $page_size   = c('page_size');     #分页条数
            $page        = com_cur_page($total, $page,  $page_size);   #当前页
			$page_data   = com_page_data($total, $page,  $page_size);   #分页原始数据
            
            //列表数据
			$start       = ($page - 1) * $page_size;
			$sql        .= " order by u.id desc limit $start, $page_size";
			$field       = " u.name , oqp.* ";
			$sql_list    = str_replace("[1]", $field, $sql);
            $list        = Db::query($sql_list, $param);
            
            //格式数据
            foreach($list as $k => $v){                
                
                $list[$k]['create_time']    =  com_format_time( $v['create_time'] );
                
                
                
                
                $list[$k]['is_lianxu']           =  c( "type.is_lianxu" , $v['is_lianxu'] );
                
                
            }
			$com_body    = com_build_table($list, array( "name", "is_lianxu", "points", "create_day","create_time" ));
			$com_page    = com_build_page( $page_data );
			$data = array(
				"com_body"  => $com_body,
				"com_page"  => $com_page,
			);
            $config = [
                'data'   => $data,
            ];
			com_check($config);
        }        
        
        
        $data = [
            
            'is_lianxu'    => ['100all'=>'全部签到类型'] + c('type.is_lianxu'),
            'nav'       => ['签到记录', '列表'],
        ];
        return view('', $data);
    }
    
 
}